<?php
/**
 * Created by PhpStorm OF yuyi.
 * User: YUYI
 * Date: 2018/5/14 0014
 * Time: 下午 4:16
 * Administrator
 */

namespace app\common\service;


class UserService extends BaseService
{
    /**
     * 获取当前用户信息
     * @return bool|mixed
     */
    public static function getCurrentUserInfo()
    {
        if (session('?userId')){
            $userid = session('userId');
            return cache('userInfo'.$userid);
        }else{
            return false;
        }
    }

    /**
     * 设置当前用户信息
     * @param $user
     * @return bool
     */
    public static function setUserInfo($user)
    {
        $userid = $user['userId'];
        session('userId',$user['userId']);
        if (cache('?userInfo'.$userid)){
            return false;
        }
        cache('userInfo'.$userid,$user);
        return true;
    }

    /**
     * 删除当前用户信息
     * @return bool
     */
    public static function delUserInfo()
    {
        if (session('?userId')){
            $userid = session('userId');
            cache('userInfo'.$userid,null);
            session('userId',null);
            return true;
        }else{
            return false;
        }
    }

    public static function updateUserInfo($user)
    {
        $userid = $user['userId'];
        session('userId',$user['userId']);
        cache('userInfo'.$userid,$user);
        return true;
    }
}